home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.6 KB | 115 lines | [TEXT/ttxt] |
- --<<<
- -- first create a window
- object myWindow (Window)
- boundary:(new Rect x2:200 y2:200)
- settings x:300, y:50
- end
- show myWindow
-
- -- create a space to control actuators in the window
- object myActuatorController (ActuatorController)
- enabled:true, space:myWindow, wholeSpace:true
- end
-
- @down
- @up -- declare name literals first, good programming practice
-
- -- create the SimpleButton class
- class SimpleButton (TwoDShape, Actuator)
- instance variables
- authorData
- activateAction
- pressAction
- releaseAction
- currentState -- either @up or @down
- instance methods
-
- method init self #rest args -> (
- apply nextMethod self args
-
- self.currentState := @up
- )
- end
-
- -- the actuator controller calls activate, press, and release
- -- on this button as it receives mouse events. Specialize these
- -- three methods, which are defined by Actuator
- -- could also specialize multiActivate here
- method activate self {class SimpleButton} -> (
-
- nextmethod self
-
- if self.enabled == false then (
- return self
- ) else (
- self.currentState := @up
- self.fill := whiteBrush
- handleActivate self
- return self
- )
- )
- method press self {class SimpleButton} -> (
-
- nextmethod self
-
- if self.enabled == false then (
- return self
- ) else (
- self.currentState := @down
- self.fill := blackBrush
- handlePress self
- return self
- )
- )
- method release self {class SimpleButton} -> (
-
- nextmethod self
-
- if self.enabled == false then (
- return self
- ) else (
- self.currentState := @up
- self.fill := whiteBrush
- handleRelease self
- return self
- )
- )
-
- -- although it is not required, the activate, press, and release
- -- methods are factored just like in PushButton and Toggle
- method handleActivate self {class SimpleButton} -> (
- if self.activateAction <> undefined do (
- self.authorData := "activate"
- (self.activateAction) (self.authorData) self
- )
- return self
- )
- method handlePress self {class SimpleButton} -> (
- if self.pressAction <> undefined do (
- self.authorData := "press"
- (self.pressAction) (self.authorData) self
- )
- return self
- )
- method handleRelease self {class SimpleButton} -> (
- if self.releaseAction <> undefined do (
- self.authorData := "release"
- (self.releaseAction) (self.authorData) self
- )
- return self
- )
-
- -- now create an instance of SimpleButton and append it to the window
- object myButton (SimpleButton)
- boundary:(New Oval x2:100 y2:100), stroke:blackBrush
- settings x:50,y:50
- end
- append myWindow myButton
-
- -- set up a function for activateAction, pressAction, and releaseAction
- function beep x y -> format debug "beep %*\n" x @normal
- myButton.activateAction := beep
- myButton.pressAction := beep
- myButton.releaseAction := beep
- -->>>
-